<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
  <h1>商品列表</h1>
  <table border="1">
    <th>id</th>
    <th>商品标题</th>
    <th>商品价格</th>
    <th>商品库存</th>
    <tr v-for="p in arr">
      <td>{{p.id}}</td>
      <td>{{p.title}}</td>
      <td>{{p.price}}</td>
      <td>{{p.num}}</td>
        <td><a :href="'/update.html?id='+p.id" >修改</a></td>
        <td><a href="javascript:void(0)" @click="del(p.id)">删除</a></td>
    </tr>
  </table>

</div>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
 <script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
     <script>
         let v = new Vue({
             el:"body>div",
             data:{
               arr:[{id:"1",title:"女的",price:5,num:100},{id:"2",title:"女的",price:5,num:100},
                 {id:"3",title:"女的",price:5,num:100}]
             },
             methods:{
                 del(id){
                     if(confirm("确认删除")){
                         axios.get("/delete?id="+id).then(function (response) {
                             //刷新页面
                             location.reload();
                         })
                     }

                 }
             },
           created:function (){
               //created方法是Vue对象中内置的方法，当Vue对象初始化时会调用此法
             //通常情况下把进入页面后立即发出请求
             console.log("女朋友没了")
             axios.get("/select").then(function (response) {
               //这里得到的服务器响应的数据是一个数组里面的多个商品
               v.arr=response.data

             })
           }

         })
     </script>
</body>
</html>